<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<link rel="STYLESHEET" href="lib.css" type="text/css">
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png">
<link rel="start" href="../index.html" title="Python documentation Index">
<link rel="first" href="lib.html" title="Python library Reference">
<link rel="contents" href="contents.html" title="Contents">
<link rel="index" href="genindex.html" title="Index">
<link rel="last" href="about.html" title="About this document...">
<link rel="help" href="about.html" title="About this document...">
<link rel="prev" href="module-shutil.html">
<link rel="parent" href="filesys.html">
<link rel="next" href="archiving.html">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="aesop" content="information">
<title>11.11 dircache -- Cached directory listings</title></head>

<body>
<div class="navigation">
<div id="top-navigation-panel" xml:id="top-navigation-panel">
<table align="center" cellpadding="0" cellspacing="2" width="100%">
<tbody><tr>
<td class="online-navigation"><a rel="prev" title="11.10.1 Example" href="shutil-example.html"><img src="../icons/previous.png" alt="Previous Page" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a rel="parent" title="11. file and Directory" href="filesys.html"><img src="../icons/up.png" alt="Up one Level" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a rel="next" title="12. data Compression and" href="archiving.html"><img src="../icons/next.png" alt="Next Page" border="0" height="32" width="32"></a></td>
<td align="center" width="100%">Python库参考</td>
<td class="online-navigation"><a rel="contents" title="Table of Contents" href="contents.html"><img src="../icons/contents.png" alt="Contents" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a href="modindex.html" title="Module Index"><img src="../icons/modules.png" alt="Module Index" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a rel="index" title="Index" href="genindex.html"><img src="../icons/index.png" alt="Index" border="0" height="32" width="32"></a></td>
</tr></tbody></table>
<div class="online-navigation">
前一节：<a class="sectref" rel="prev" href="shutil-example.html">11.10.1 例子</a> 上一级：
<a class="sectref" rel="parent" href="filesys.html">11. 文件和目录</a> 下一节：
<a class="sectref" rel="next" href="archiving.html">12.数据压缩和归档</a><a class="sectref" rel="next" href="archiving.html"></a>
</div>
<hr></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION00131100000000000000000">
11.11 <tt class="module">dircache</tt> --
         缓存的目录列表</a>
</h1>

<p>
<a name="module-dircache"></a>

</p><p><tt class="module">dircache</tt> 模块定义一个使用缓存读取目录列表的函数，并且使用目录的 <var>mtime</var> 是缓存失效，另外，它定义一个通过附加一个斜线注释是否是目录的函数。

</p><p><tt class="module">dircache</tt> 模块定义下列函数：</p><dl><dt><table cellpadding="0" cellspacing="0"><tbody><tr valign="baseline">
  <td><nobr><b><tt id="l2h-2313" xml:id="l2h-2313" class="function">reset</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></tbody></table></dt>
<dd>重置目录缓存。
</dd></dl>

<p>
</p><dl><dt><table cellpadding="0" cellspacing="0"><tbody><tr valign="baseline">
  <td><nobr><b><tt id="l2h-2314" xml:id="l2h-2314" class="function">listdir</tt></b>(</nobr></td>
  <td><var>path</var>)</td></tr></tbody></table></dt>
<dd>返回 <var>path</var> 的目录列表，<tt class="function">os.listdir()</tt>一样。注意除非 <var>path</var> 改变，再次调用 <tt class="function">listdir()</tt> 将不在重新读取目录结构。

<p>注意返回的列表应该仅被视为只读。(可能将来的版本可以该变它返回一个元组？)
</p></dd></dl>

<p>
</p><dl><dt><table cellpadding="0" cellspacing="0"><tbody><tr valign="baseline">
  <td><nobr><b><tt id="l2h-2315" xml:id="l2h-2315" class="function">opendir</tt></b>(</nobr></td>
  <td><var>path</var>)</td></tr></tbody></table></dt>
<dd>同<tt class="function">listdir()</tt>一样。它的定义是为了向后的兼容性。
</dd></dl>

<p>
</p><dl><dt><table cellpadding="0" cellspacing="0"><tbody><tr valign="baseline">
  <td><nobr><b><tt id="l2h-2316" xml:id="l2h-2316" class="function">annotate</tt></b>(</nobr></td>
  <td><var>head, list</var>)</td></tr></tbody></table></dt>
<dd>假定 <var>list</var> 是相对于 <var>head</var> 的路径的一个列表，并且在合适的位置，每一个指向目录的路径都会被添加一个&nbsp; "<tt class="character">/</tt>" 。</dd></dl><div class="verbatim"><pre>&gt;&gt;&gt; import dircache<br>&gt;&gt;&gt; a = dircache.listdir('/')<br>&gt;&gt;&gt; a = a[:] # Copy the return value so we can change 'a'<br>&gt;&gt;&gt; a<br>['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+<br>found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']<br>&gt;&gt;&gt; dircache.annotate('/', a)<br>&gt;&gt;&gt; a<br>['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/<br>', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm<br>linuz']<br></pre></div>

<p>

</p><div class="navigation">
<div class="online-navigation">
<p></p><hr>
<table align="center" cellpadding="0" cellspacing="2" width="100%">
<tbody><tr>
<td class="online-navigation"><a rel="prev" title="11.10.1 Example" href="shutil-example.html"><img src="../icons/previous.png" alt="Previous Page" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a rel="parent" title="11. file and Directory" href="filesys.html"><img src="../icons/up.png" alt="Up one Level" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a rel="next" title="12. data Compression and" href="archiving.html"><img src="../icons/next.png" alt="Next Page" border="0" height="32" width="32"></a></td>
<td align="center" width="100%">Python库参考</td>
<td class="online-navigation"><a rel="contents" title="Table of Contents" href="contents.html"><img src="../icons/contents.png" alt="Contents" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a href="modindex.html" title="Module Index"><img src="../icons/modules.png" alt="Module Index" border="0" height="32" width="32"></a></td>
<td class="online-navigation"><a rel="index" title="Index" href="genindex.html"><img src="../icons/index.png" alt="Index" border="0" height="32" width="32"></a></td>
</tr></tbody></table>
<div class="online-navigation">
前一节：<a class="sectref" rel="prev" href="shutil-example.html">11.10.1 例子</a> 上一级：
<a class="sectref" rel="parent" href="filesys.html">11. 文件和目录</a> 下一节：
<a class="sectref" rel="next" href="archiving.html">12.数据压缩和归档</a>
</div>
</div>
<hr>
<span class="release-info">2.5.1 版， 文档更新在 2007，4，18。翻译：<a href="http://www.zkfarmer.org/">zkfarmer</a>。</span>
</div>
<!--End of Navigation Panel-->
<address>
关于建议修改的信息查阅 <i><a href="about.html">关于这个文档...</a></i>。
</address>
</body></html>